import { BrowserWindow, globalShortcut } from 'electron'
// import { OsBridge } from 'os-bridge'
// type OsBridge = typeof OsBridge
export class AppGlobalShortcut {
  win: any
  type: number = 0
  //   osBridge: OsBridge | null = null

  constructor(win: BrowserWindow) {
    this.win = win
    // this.osBridge = new OsBridge('test')
    console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
    // let list = this.osBridge.getInputMethodListHandler();
    // console.log(list)
    console.log('菜单数据显示结束 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
    // let resp = this.osBridge.batchDisable()
    // console.log(resp, 'resp')
  }

  listen() {
    //判断窗口最大化的函数
    // win.isMaximized()
    //监听窗口最大化
    this.win.on('maximize', () => {
      console.log('maximize')
      // this.win.webContents.send('mainWin-max', true)
      // this.osBridge.setTaskbarStatus(true)
      // this.win.setFullScreen(true)
    })

    // 最小化事件
    this.win.on('unmaximize', () => {
      console.log('unmaximize')
      // this.win.webContents.send('mainWin-max', false)
      // this.osBridge.setTaskbarStatus(true)
    })
  }

  // 初始化全局快捷键
  initGlobalShortcut() {
    // 全屏
    globalShortcut.register('CommandOrControl+F11', () => {
      console.log('CommandOrControl+F11')
      if (this.win.isFullScreen()) {
        this.exitFullScreen()
      } else {
        this.enterFullScreen()
      }
    })

    // 安 Escape 键退出全屏
    globalShortcut.register('Escape', () => {
      // console.log('escape ==== ')
      this.win.setAlwaysOnTop(false)
      this.win.setFullScreen(false)
      this.win.restore()
    })

    globalShortcut.register('Alt+CommandOrControl+I', () => {
      console.log('Alt+CommandOrControl+I!')
      this.win.setFullScreen(true)
      this.win.setAlwaysOnTop(true)
    })

    // 安 CommandOrControl + A 键
    globalShortcut.register('CommandOrControl+A', () => {
      console.log('CommandOrControl+A!')
    })
  }

  // 进入全屏
  enterFullScreen() {
    // 隐藏任务栏
    // let resp = this.osBridge.batchDisable()
    // console.log(resp)

    // 全屏
    this.win.setFullScreen(true)
    // 置顶
    this.win.setAlwaysOnTop(true, 'pop-up-menu')
    // 启用键盘钩子
    // this.osBridge.keyboardHookProcHandler(true)
  }

  // 退出全屏
  exitFullScreen() {
    // 取消全屏
    this.win.setFullScreen(false)
    // 取消置顶
    this.win.setAlwaysOnTop(false)
    // 启用功能
    // let resp = this.osBridge.batchEnable()
    // console.log(resp)
  }
}

export default AppGlobalShortcut
